#include<fstream>
#include<stdio.h> 
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");


void swap(int * a,int * b){
	int  * temp = new(int);  
	* temp = * a;
	* a = * b;
	* b = * temp;
}

void MAX_HEAPIFY(int *a,int i,int n){ // 来源于算法导论 
	int left = (2*(i+1) - 1);
	int right = (2*(i+1));
	int largest;
	if((left <= n-1)&&(*(a+left) > *(a+i)))
		largest = left;
	else largest = i;
	if((right <= n-1)&&(*(a+right) > *(a+largest)))
		largest  = right;
	if(largest != i) {
		swap((a+largest),(a+i));
		MAX_HEAPIFY(a,largest,n);
	}		
	
} 

void BUILD_MAX_HEAP(int *a,int n){ // 来源于算法导论 
	int i;
	for(i = n/2;i>=0;i--)
		MAX_HEAPIFY(a,i,n);
}

int HEAP_MAXIMUM(int *a){
	return *(a);
} 

void HEAPSORT(int *a,int n){
	int i;
	for(i = n-1;i>=1;i--){
		swap(a[0],a[i]);
		n = n - 1;
		MAX_HEAPIFY(a,0,n);

	}
}

int HEAP_EXTRACT_MAX(int *a,int n){
	if(n < 0) fout<<"error"<<endl;
	int max = a[0];
	a[0] = a[n-1];
	n--;
	MAX_HEAPIFY(a,0,n);
	return max;
}

int main(){
	
	int i,m,n;
	fin>>n; 
	int *num = new int [n]; // 指针传值 
	int *d = new int [n];
	int *s = new int [n];
	
	for(i=0;i<n;i++){
		fin>>m;
		num[i] = m;
	}
	
	BUILD_MAX_HEAP(num,n);
	//HEAP_EXTRACT_MAX(num,n);
	//HEAPSORT(a,n);
	for(i=0;i<n;i++)
		*(d+i) = *(num+i);
	for(i=0;i<n;i++)
		*(s+i) = *(num+i);
		
	for(i=0;i<n;i++){
		fout<<HEAP_EXTRACT_MAX(d,n)<<"  delete"<<endl;
		fout<<d[0]<<endl;
	}
	

	

	HEAPSORT(s,n);
	fout<<"sort"<<endl;
	
	for(i=0;i<n;i++){
		
		fout<<s[i]<<endl;
	}
	
	return 0;
}
